﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Refugees.Views.Windows
{
    /// <summary>
    /// Логика взаимодействия для Authorization2Reg.xaml
    /// </summary>
    public partial class Authorization : Window
    {
        Repositories.UserRepository userRepository = new Repositories.UserRepository();
        public Authorization()
        {
            InitializeComponent();
        }

        private void LoginClick(object sender, RoutedEventArgs e)
        {
            var user = userRepository.Login(Login.Text, Password.Password);
            
            if (user == null || user.Id == 0)
            {
                MessageBox.Show("Неверный логин или пароль");
                return;
            }
            Repositories.ModelRepository.User = user;
            Repositories.ModelRepository.PersonalData = user.PersonalData.FirstOrDefault();
            MessageBox.Show("Вы успешно вошли.");
            new About().Show();
            Close();
        }

        private void Registration(object sender, RoutedEventArgs e)
        {
            new Registration().Show();
            Close();
        }
    }
}
